package com.example.springbootweb.controller;


import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class loginController {

    //@RequestMapping(value = "/user/login", method = RequestMethod.POST)
    @PostMapping(value = "/user/login")
    public String login(@RequestParam("Username") String usename,
                        @RequestParam("Password") String password,
                        Map<String, Object> map, HttpSession session){
        if(!StringUtils.isEmpty(usename) && "123456".equals(password)){
            //登录成功,为防止重复提交，可以重定向到主页
            session.setAttribute("LoginUser",usename);
            return "redirect:/main.html";
        }else{
            //登录失败
            map.put("msg","登录失败！！！");
            return "index";
        }

    }
}
